<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@page import="Logic.Authorizer"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<!DOCTYPE html>
<head>
<title>New Process</title>
<style>
input[type=text] {
	margin: 2%;
}
fieldset{
    margin:2% !important;
}

</style>
</head>
<%
	if (session.getAttribute("name") == null) {
		response.sendRedirect("login.jsp");
	} else {
		if (!Authorizer.checkRole("2", session.getAttribute("role")
				.toString())) {
			response.sendRedirect("nopermission.jsp");
		}
	}
%>
<jsp:include page="t_header.jsp" />

<!--  <div class="breadcrumbs_container">
	<article class="breadcrumbs"> <a href="Proc_NewProcess.jsp">Manage Processes</a>
	<div class="breadcrumb_divider"></div>
	<a class="current">New Process</a> 
	</article>
</div> -->
<jsp:include page="header.html" />

<!-- Declare sidebar -->
<jsp:include page="t_sidebarProcess.jsp" />

<!-- Main Content -->
<body>
	<section id="main" class="column">

		<article class="module width_3_quarter">
			<form id="SingleNewProcess" action="SingleNewProcess.jsp"
				method="post" enctype="multipart/form-data">
				<header>
					<h3>Add New Process</h3>
				</header>
				<div class="module_content">
					<fieldset>
						<label>Category</label> <select name="Category" id="Category"
							style="width: 80%">
							<option value="KeyProcesses">Key Process</option>
							<option value="SupportingProcesses">Supporting Process</option>
						</select>
					</fieldset>
					<fieldset>
						<label>Process Name</label> <input id="ProcessName"
							name="ProcessName" style="width: 80%" type="text"
							onChange="CheckProcess(this.value, this)">
					</fieldset>
					<fieldset style="width: 48%; float: left; margin-right: 3%;">
						<label>Code</label> <input id="Code" name="Code"
							style="width: 80%" type="text" onChange="CheckProcess(this.value, this)">
					</fieldset>
					<fieldset style="width: 48%; float: left;">
						<label>Procedure Name</label> <input id="ProcedureName"
							name="ProcedureName" style="width: 80%" type="text"
							onChange="CheckProcess(this.value, this)">
					</fieldset>
					<fieldset style="width: 100%; float: left; margin-bottom: 2%;">
						<label>Procedure File</label>
						<div style="width: 80%; margin:2%;">
							<input id="ProcedureFile" type="file" name="ProcedureFile"
								style="width: 85%">
						</div>
					</fieldset>
					<div class="clear"></div>
					<fieldset>
						<label>Effective Date</label> <input name="effectivedate"
							type="text" id="inputField" style="width: 80%"
							readonly="readonly" />
					</fieldset>
					<div class="clear"></div>
				</div>
				<footer>
					<div class="submit_link">
						<input id="Add" type="submit" value="Add"
							onclick="return verifyData()" class="alt_btn"> <input
							id="Clear" type="reset" value="Clear" onclick="Clear()"
							class="alt_btn">
					</div>
				</footer>
			</form>
		</article>
		<script type="text/javascript">
			function verifyData() {
				if (CheckSpecial() == false) {
					alert('Please ensure that all entered text does not contain special characters. ');
					return false;
				} else {
					if ($('#ProcedureFile').val() == ""
							|| $('#ProcessName').val() == ""
							|| $('#Code').val() == ""
							|| $('#ProcedureName').val() == ""
							|| $('#inputField').val() == "") {
						alert('Please ensure that all fields are filled in and document is selected.');
						return false;
					} else {
						alert('File selected: ' + $('#ProcedureFile').val());
						var form = document.getElementById('SingleNewProcess');
						form.action = "SingleNewProcess.jsp?Category="
								+ document.getElementById('Category').value
								+ "&ProcessName="
								+ document.getElementById('ProcessName').value
								+ "&Code="
								+ document.getElementById('Code').value
								+ "&ProcedureName="
								+ document.getElementById('ProcedureName').value
								+ "&EDate="
								+ document.getElementById('inputField').value;
						form.submit();
						return true;
					}
				}
			}

			function Clear() {
				document.getElementById('SingleUpload').reset();
				return false;
			}

			function CheckProcess(str, object) {
				var iChars = "~`!#$%^*+=[]\\\';,/{}|\":<>?";
				object.style.backgroundColor = "#FFF";
				for ( var i = 0; i < str.length; i++) {
					if (iChars.indexOf(str.charAt(i)) != -1) {
						object.style.backgroundColor = "#FA5858";
						alert("Special characters like ~`!#$%^*+=[]\\\';,/{}|\":<>? \nare not allowed!\n");
						object.focus();
						object.select();
						break;
					}
				}
			}

			function CheckSpecial() {
				var iChars = "~`!#$%^*+=[]\\\';,/{}|\":<>?";
				var ProcessObj = document.getElementById('ProcessName').value;
				var CodeObj = document.getElementById('Code').value;
				var ProcedureObj = document.getElementById('ProcedureName').value;
				var ConcateVal = ProcessObj + CodeObj + ProcedureObj;
				var result = true;
				for ( var i = 0; i < ConcateVal.length; i++) {
					if (iChars.indexOf(ConcateVal.charAt(i)) != -1) {
						result = false;
						break;
					}

				}
				return result;
			}
		</script>
		<div class="spacer"></div>
	</section>
	<!-- Declare closing tags -->
	<jsp:include page="t_footer.jsp" />